package pre;

import java.util.HashMap;

/**
 * @program: leetcode
 * @author: jzhou
 * @date: 2022-10-27 18:59
 * @version: 1.0
 * @description: 位操作运算
 **/
public class BaseOperator {
	public static void main(String[] args) {
		int a1 = 5; // 0000 0101
		int b1 = 3; // 0000 0011
		a1 |= b1; // 0000 00111
		System.out.println("|= "+a1);

		int a2 = 5; // 0000 0101
		int b2 = 3; // 0000 0011
		a2 &= b2; // 0000 0001
		System.out.println("&= "+a2);

		int a3 = 5; // 0000 0101
		int b3 = 3; // 0000 0011
		a3 ^= b3; // 0000 0110
		System.out.println("^= "+a3);
	}

	static int MAXIMUM_CAPACITY = 1 << 30;
	// 以25 为例
	static int tableSizeFor(int cap) {
		int n = cap - 1; // 0001 1000 (24)
		n |= n >>> 1; //    0000 1100 (12) => 0001 1100 (28)
		n |= n >>> 2; //                      0000 0111 (7) => 0001 1111 (31)
		n |= n >>> 4; //                                       0000 0001  =>  0001 1111 (31)
		n |= n >>> 8;
		n |= n >>> 16;
		return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; //32
	}


}
